<!--
 * @Author: wangjh wangjiahui0710@163.com
 * @Date: 2024-06-11 11:33:53
 * @LastEditors: wangjh wangjiahui0710@163.com
 * @LastEditTime: 2024-06-17 14:06:58
 * @FilePath: \cip-admin\src\pages\park\enterprises\corporate-blacklist\components\filter.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script lang="ts" setup>
import { injectState } from "../state";
import { whManagerBsTbEnterpriseGetListUsingPost } from "@/genapi/wh";
import { computedLoading } from "@/hooks/computed-loading";

defineOptions({ name: "Filters" });

const {
	filter,
	page: { isLoading },
} = injectState()!;

const initial = { ...toRaw(filter.value) };
const data = ref({ ...initial });

const search = () => {
	filter.value = { ...toRaw(data.value) };
};

const reset = () => {
	data.value = { ...initial };
};

const [state] = computedLoading(async () => {
	const { data } = await whManagerBsTbEnterpriseGetListUsingPost({ data: {} });
	return data?.map((item) => ({ label: item.name, value: item.name })) ?? [];
});
</script>

<template>
	<el-form class="filter-form" inline :model="data" :disabled="isLoading">
		<el-form-item label="企业名称">
			<el-select-v2
				v-model="data.name"
				clearable
				:options="state ?? []"
				class="w-240px!"
				placeholder="全部"
			/>
		</el-form-item>
		<el-form-item label="创建时间" prop="创建时间">
			<el-date-picker
				v-model="data.createTimeStart"
				clearable
				type="date"
				class="w-240px!"
				placeholder="开始日期"
				value-format="YYYY-MM-DD HH:mm:ss"
				format="YYYY-MM-DD HH:mm:ss"
			/>
		</el-form-item>
		<el-form-item label="—" prop="—">
			<el-date-picker
				v-model="data.createTimeEnd"
				clearable
				type="date"
				class="w-240px!"
				placeholder="结束日期"
				value-format="YYYY-MM-DD HH:mm:ss"
				format="YYYY-MM-DD HH:mm:ss"
			/>
		</el-form-item>

		<el-form-item>
			<el-divider direction="vertical" h="32px!" m="r-22px!" />
			<el-button type="primary" :loading="isLoading" @click="search">
				<template #icon>
					<el-icon class="i-custom:search" />
				</template>
				查询
			</el-button>
			<el-button @click="reset">
				<template #icon>
					<el-icon class="i-custom:reset" />
				</template>
				重置
			</el-button>
		</el-form-item>
	</el-form>
</template>
